<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="plugins/elementui/index.css">
        <link rel="stylesheet" href="css/login.css">
        <style>
            .el-row{
                margin: 5px 0;
            }
            #submit{
                cursor: pointer;
                text-align: center;
                margin-left: 85px;
            }
        </style>
    </head>
    <body class="hold-transition skin-purple sidebar-mini">
        <div id="app">
            <div class="login-container">
                <div class="loginBox">
                  <form method="post" class="login-form" action="/login.do" label-position="left">
                      <div class="title-container">
                        <div class="logoInfo clearfix">
                          <em class="logo"></em>
                        </div>
                      </div>
                      <div>
                          <el-row>
                              <el-col :span="18">
                                    <el-input v-model="form.username" @blur="getRole" name="username" placeholder="请输入用户名"></el-input>
                              </el-col>
                          </el-row>
                      </div>
                      <div>
                          <el-row>
                              <el-col :span="18">
                                  <el-input type="password" v-model="form.password" name="password" placeholder="请输入密码"></el-input>
                              </el-col>
                          </el-row>
                      </div>
                      <div>
                          <el-select  v-model="form.region" placeholder="请选择活动区域">
                            <el-option v-for="item in roleList"
                                       :label="item.name"
                                       :value="item.id"/>
                          </el-select>
                      </div>
                      <el-row>
                          <el-col :span="8">
                              <!--<el-button type="primary" id="submit" @click="login()">登录</el-button>-->
                              <el-input type="submit" value="登录"/>
                          </el-col>
                      </el-row>
                </form>
                </div>
              </div>
        </div>
    </body>
    <!-- 引入组件库 -->
    <script src="js/vue.js"></script>
    <script src="plugins/elementui/index.js"></script>
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script src="js/axios-0.18.0.js"></script>

    <script>
        new Vue({
            el:"#app",
            data:{
                form:{},
                roleList:[]
            },
            methods:{
                getRole() {
                    var role = this.form.region;
                    var name = this.form.username;

                    this.roleList = [];

                    if(!name) {
                        this.$message.error("请输入用户名!");
                        return;
                    }
                    axios.get('/role/getRoleList.do?name='+name).then((res)=>{
                        if(res.data.flag) {
                            this.roleList = res.data.data;
                        }
                    });
                },
                //权限不足提示
                showMessage(r){
                    if(r.message == 'Request failed with status code 403'){
                        //权限不足
                        this.$message.error('用户名或密码错误');
                        return;
                    }else{
                        this.$message.error('未知错误');
                        return;
                    }
                },
                login() {
                    var id = this.form.region;
                    alert(id);
                    axios.post('/login.do',this.form).then((res)=>{

                    }).catch((r)=>{
                        this.showMessage(r);
                    })
                }
            }
        });
    </script>
</html>
